const Router = require('koa-router');
const router = new Router({
    prefix: '/v1/user/'
});
const { ValidationRegister } = require('../../validators/validators.js');
const { User } = require('../../models/User.js');
const { HttpSuccess } = require('../../core/httpError.js');
router.post('register', async (ctx, next) => {
    // let params = ctx.params;
    // let query = ctx.query;
    // let header = ctx.header;
    // console.log(params);
    // console.log(query);
    // console.log(header);
    // console.log(ctx.request.body);
    // if (true) {
    //     // const getError = new Error();
    //     // getError.status = 400;
    //     // getError.code = 200;
    //     // getError.msg = '无效参数';
    //     // throw getError;
    // }
    const correct = await new ValidationRegister().validate(ctx);
    const user = {
        id: correct.get('body.id'),
        nickname: correct.get('body.nickname'),
        email: correct.get('body.email'),
        password: correct.get('body.password')
    }
    User.create(user).then(res => {
        console.log('res', res);
    }).catch(err => {
        console.log('err', err);
    });


    throw new HttpSuccess();
})

module.exports = router;